package com.huawei.hianalytics.ab.bc.hi;

import java.util.Calendar;
import java.util.UUID;

public class bc {
    private long ab = 1800000;
    private long bc = 30000;
    private volatile boolean cd = false;
    private volatile long de = 0;
    private ab ef = null;

    class ab {
        String ab = UUID.randomUUID().toString().replace("-", "");
        boolean bc;
        final /* synthetic */ bc cd;
        private long de;

        ab(bc bcVar, long j) {
            this.cd = bcVar;
            this.ab += "_" + j;
            this.de = j;
            this.bc = true;
            bcVar.cd = false;
        }

        private boolean ab(long j, long j2) {
            Calendar instance = Calendar.getInstance();
            instance.setTimeInMillis(j);
            Calendar instance2 = Calendar.getInstance();
            instance2.setTimeInMillis(j2);
            return (instance.get(1) == instance2.get(1) && instance.get(6) == instance2.get(6)) ? false : true;
        }

        private void bc(long j) {
            com.huawei.hianalytics.ab.bc.ef.ab.bc("SessionWrapper", "getNewSession() session is flush!");
            this.ab = UUID.randomUUID().toString();
            this.ab = this.ab.replace("-", "");
            this.ab += "_" + j;
            this.de = j;
            this.bc = true;
        }

        private boolean bc(long j, long j2) {
            return j2 - j >= this.cd.ab;
        }

        void ab(long j) {
            if (this.cd.cd) {
                this.cd.cd = false;
                bc(j);
            } else if (bc(this.de, j) || ab(this.de, j)) {
                bc(j);
            } else {
                this.de = j;
                this.bc = false;
            }
        }
    }

    public String ab() {
        if (this.ef != null) {
            return this.ef.ab;
        }
        com.huawei.hianalytics.ab.bc.ef.ab.cd("SessionWrapper", "getSessionName(): session not prepared. onEvent() must be called first.");
        return "";
    }

    void ab(long j) {
        if (this.ef == null) {
            com.huawei.hianalytics.ab.bc.ef.ab.bc("SessionWrapper", "Session is first flush");
            this.ef = new ab(this, j);
            return;
        }
        this.ef.ab(j);
    }

    public boolean bc() {
        if (this.ef != null) {
            return this.ef.bc;
        }
        com.huawei.hianalytics.ab.bc.ef.ab.cd("SessionWrapper", "isFirstEvent(): session not prepared. onEvent() must be called first.");
        return false;
    }

    public void cd() {
        this.ef = null;
        this.de = 0;
        this.cd = false;
    }
}
